#include "AnimationManager.h"



#include "MainMenuState.h"

#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"

#include "../tinyxml/tinyxml.h"
#include "../tinyxml/tinystr.h"


//using namespace std;


CAnimationManager* CAnimationManager::GetInstance( void )
{

	// Lazy Instantiation
	static CAnimationManager s_Instance;

	return &s_Instance;
}

CAnimationManager::CAnimationManager(void)
{





}

CAnimationManager::~CAnimationManager(void)
{

}

bool CAnimationManager::LoadFromFile(const char* szFileName)
{
	TiXmlDocument doc;

	if( doc.LoadFile( szFileName ) == false )
		return false;

	TiXmlElement* pRoot = doc.RootElement();

	if( pRoot == nullptr )
		return false;



	TiXmlElement * pNodeFrame  = pRoot->FirstChildElement("Animations");


	while( pNodeFrame != nullptr )
	{
		

		

		for(int x = 0; x< 7; x++)
		{
			//CAnimation* temp = new CAnimation();

			AniObj = new CAnimation();


			TiXmlElement * pNode  = pNodeFrame->FirstChildElement("Frames");

			for(int i = 0; i<6; i++)
			{

				tFrame* frame = new tFrame;

				TiXmlElement* pNodeAnimation = pNode->FirstChildElement( "SourceRect" );


				pNodeAnimation->Attribute("RenderLeft",		  (int*)&frame->m_rRenderRect.left);
				pNodeAnimation->Attribute("RenderTop",	      (int*)&frame->m_rRenderRect.top);
				pNodeAnimation->Attribute("RenderRight",	  (int*)&frame->m_rRenderRect.right);
				pNodeAnimation->Attribute("RenderBottom",	  (int*)&frame->m_rRenderRect.bottom);



				pNodeAnimation = pNodeAnimation->NextSiblingElement( "CollisionRect" );

				pNodeAnimation->Attribute("CollisionLeft", 		  (int*)&frame->m_rCollisionRect.left);
				pNodeAnimation->Attribute("CollisionTop",	  	  (int*)&frame->m_rCollisionRect.top);
				pNodeAnimation->Attribute("CollisionRight",		  (int*)&frame->m_rCollisionRect.right);
				pNodeAnimation->Attribute("CollisionBottom",	  (int*)&frame->m_rCollisionRect.bottom);


				pNodeAnimation = pNodeAnimation->NextSiblingElement( "ActiveRect" );

				pNodeAnimation->Attribute("ActiveLeft", 		  (int*)&frame->m_rActiveRect.left);
				pNodeAnimation->Attribute("ActiveTop",	  		 (int*)&frame->m_rActiveRect.top);
			pNodeAnimation->Attribute("ActiveRight",		  (int*)&frame->m_rActiveRect.right);
			pNodeAnimation->Attribute("ActiveBottom",	  (int*)&frame->m_rActiveRect.bottom);

			

			pNodeAnimation = pNodeAnimation->NextSiblingElement( "AnchorPoint" );

			pNodeAnimation->Attribute("X",	  &frame->m_nAnchorX);
			pNodeAnimation->Attribute("Y",	  &frame->m_nAnchorY);

			//pNodeAnimation = pNodeAnimation->NextSiblingElement( "Trigger" );

			//frame.m_sEvent = pNodeAnimation->Attribute("trigger");

			
			AniObj->frames.push_back(frame);


			pNode = pNode->NextSiblingElement( "Frames"  );
			
			
			
			}

			AllAnimations.push_back( AniObj );

			pNodeFrame = pNodeFrame->NextSiblingElement( "Animations");
			

		}


		


	}
	return false;
}

void Init()
{
	

}


void Update(float fElapsedTime)
{
	
	
	
}

void Render( )
{
	


}
